package com.zang.schema.proxy;

/**
 * 代理者，通过实现代理目标同一个接口来代替代理目标
 *
 * @author Zhang Qiang
 * @Date 2019/8/30 11:08
 */
public class Proxy implements AbstractSubject {

    private RealSubject realSubject;

    @Override
    public void request(String event) {
        if (realSubject == null){
            realSubject = new RealSubject();
        }
        proRealSubject();
        realSubject.request(event);
        postRealSubject();
    }

    public void proRealSubject(){
        System.out.println("访问正常对象之前的预处理");
    }

    public void postRealSubject(){
        System.out.println("访问正常对象之后的后续处理");
    }

}
